This class is used for reading configuration files:
- Reads a std::istream to builds a std::map of <key, record>
- Simple syntax based on = ( ) { } “ , ; % focused on flexible value setting.
- each
record is a list of values
- Provides values upon requests with function set(key, index) .
- A counter records the usage of the values.
Notes:
- There can be an arbitrary number of Keys, and an abitrary number of values for each key.
- Values are kept as strings, and are converted at request by templated functions:
template <
typename T>
int set(T & ptr, std::string key)
key is the name under which the value appeared,
- The template argument
T defines the type of the parameter, and the value-string is interpreted accordingly,
- The interpreted value is stored in
ptr,
- Returns 1 if
ptr was set successfully, 0 otherwise
- The method warning() can report values that have not been used, or that have been used more than once.
Class reviewed by Andre Clapson on 10.03.2011.
- Todo:
- parse and instantiate values like 'random.uniform()' or 'PI*30' or '0.1/60'
|
|
| Glossary () |
| | initialize
|
| |
|
| Glossary (std::istream &in) |
| | this constructor calls read(in)
|
| |
|
| Glossary (const std::string &) |
| | this constructor calls read()
|
| |
|
bool | empty () const |
| | true if no key were set
|
| |
|
unsigned | nb_keys () const |
| | number of keys
|
| |
|
bool | has_key (key_type const &) |
| | return true if key is present, even if no value was set
|
| |
|
bool | use_key (key_type const &) |
| | return true if key is present; the key is deleted
|
| |
|
void | erase (key_type const &) |
| | remove given key
|
| |
|
void | clear () |
| | clear all entries
|
| |
|
Glossary | extract (key_type const &) |
| | create a new Glossary with only the given key
|
| |
|
unsigned | nb_values (key_type const &) |
| | return number of values associated with a key
|
| |
|
rec_type * | values (key_type const &) |
| | gives a pointer to the values corresponding to a key, or null if the key is not present
|
| |
|
rec_type const * | values (key_type const &) const |
| | gives a const pointer to the values corresponding to a key, or null if the key is not present
|
| |
|
std::string | value (key_type const &, unsigned indx) |
| | return the value corresponding to the key and the index, or the empty string
|
| |
| int | warnings (std::ostream &, unsigned threshold=1) const |
| | report unused values and values used multiple times More...
|
| |
| void | set_values (key_type const &, const std::string &rhs, int no_overwrite=2) |
| | this is equivalent to read('k = rhs') More...
|
| |
| void | read (std::istream &, int no_overwrite=2) |
| | update the glossary to include assignments stored in a stream More...
|
| |
|
void | read (const std::string &, int no_overwrite=2) |
| | update the glossary to include assignments stored in a string
|
| |
|
void | readFile (const char path[], int no_overwrite=2) |
| | read file specified in path
|
| |
| void | readStrings (int argc, char *argv[], int no_overwrite=2) |
| | a read for C-style command-line arguments More...
|
| |
|
void | write (std::ostream &) const |
| | write all [key, values]
|
| |
|
template<typename T > |
| int | set (T &var, key_type const &key, unsigned inx=0) |
| | set var from key[inx]. The counter associated to the value is incremented.
|
| |
|
template<typename T > |
| int | query (T &var, key_type const &key, unsigned inx=0) const |
| | set var from key[inx]. The counter is not changed
|
| |
|
template<typename T > |
| int | set (T *ptr, unsigned cnt, key_type const &key) |
| | set cnt values in the array ptr[], starting at key[0]
|
| |
|
template<typename T > |
| int | set (T &var, key_type const &key, KeyList< T > const &dict, unsigned inx=0) |
| | set var from key[inx], using the dictionary dict
|
| |
|
template<typename T > |
| void | set_value (key_type const &key, const T &var, int no_overwrite=2) |
| | set the first value of the key: key[0]=var.
|
| |
|
int | is_alpha (key_type const &key, unsigned inx=0) const |
| | check if value associated with key at index inx is made only of alpha characters
|
| |
| template<> |
| void | set_one (std::string &var, std::string const &val, key_type const &key) const |
| | special function for std::string arguments. More...
|
| |
| template<> |
| void | set_one (float &var, std::string const &val, key_type const &key) const |
| | special function for float More...
|
| |
| template<> |
| void | set_one (double &var, std::string const &val, key_type const &key) const |
| | special function for double More...
|
| |